package com.zijin;

import com.zijin.entity.Dept;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.InputStream;
import java.sql.ResultSet;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * Hello world!
 *
 */
public class App3
{
    public static void main( String[] args )
    {
        SqlSessionFactory ssf=new SqlSessionFactoryBuilder().build(
                App.class.getClassLoader().getResourceAsStream("mybatisConf.xml"));
//打开一个会话 ，会话会占用资源，不需要时要关闭
        SqlSession ss=ssf.openSession();
        //添加id为4的部门
        //int result=ss.insert("com.zijin.AddDept1",4);
        //System.out.println(result);

        //添加部门
//        Dept dept=new Dept(4,"swy","huanggai");
//        int result=ss.insert("com.zijin.Dao.DeptMapper.addDept2",dept);


        //查询2号部门职位是zuzhang的员工
        //Map<String, Object>map=new HashMap<>();
        //map.put("zhiwei","zuzhang");
        //map.put("deptid","2");
        //Object obj=ss.selectOne("com.zijin.Dao.DeptMapper.selectEmp",map);

        Map<String,Object> map=new HashMap<>();
        map.put("a","name");
        map.put("b","der");
        map.put("c","dept");
        map.put("d","陆彦妤");
        map.put("e","where");
        Object obj=ss.selectOne("com.zijin.Dao.DeptMapper.test",map);

        //ss.commit();//mybatis默认不提交，必须调用提交命令的方法
        //关闭会话
        ss.close();

        System.out.println(obj);
    }
}

